#include <iostream>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <string.h>

using namespace std;

int main(int argc, char *argv[])
{
    int sockfd, newsockfd;
    socklen_t clilen;
    sockaddr_in serv_addr, cli_addr;

    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if(sockfd < 0)
    {
        cout << "Could not open socket.\n";
        exit(1);
    }
    bzero((char *) &serv_addr, sizeof(serv_addr));
    int portno = 5000;
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = INADDR_ANY;
    serv_addr.sin_port = htons(portno);
    if(bind(sockfd, (sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
    {
        cout << "Could not bind.\n";
        exit(1);
    }

    listen(sockfd, 1);
    clilen = sizeof(cli_addr);
    newsockfd = accept(sockfd, (sockaddr *) &cli_addr, &clilen);
    if(newsockfd < 0)
    {
        cout << "Could not accept.\n";
        exit(1);
    }

    int SIZE = 1;
    char *buf = new char[SIZE];
    write(newsockfd, buf, SIZE);


}
